export function mul(a: number | string, b: number | string): number {
  let c = 0
  const d = a.toString()
  const e = b.toString()
  try {
    c += d.split('.')[1].length
  } catch (f) {
    c += 0
  }
  try {
    c += e.split('.')[1].length
  } catch (f) {
    c += 0
  }
  return Number(d.replace('.', '')) * Number(e.replace('.', '')) / Math.pow(10, c)
}

export function add(a: number | string, b: number | string): number {
  let c, d
  try {
    c = a.toString().split('.')[1].length
  } catch (f) {
    c = 0
  }
  try {
    d = b.toString().split('.')[1].length
  } catch (f) {
    d = 0
  }
  const e = Math.pow(10, Math.max(c, d))
  return (mul(a, e) + mul(b, e)) / e
}

export function sub(a: number | string, b: number | string): number {
  let c, d
  try {
    c = a.toString().split('.')[1].length
  } catch (f) {
    c = 0
  }
  try {
    d = b.toString().split('.')[1].length
  } catch (f) {
    d = 0
  }
  const e = Math.pow(10, Math.max(c, d))
  return (mul(a, e) - mul(b, e)) / e
}

export function div(a: number | string, b: number | string): number {
  let e
  try {
    e = a.toString().split('.')[1].length
  } catch (err) {
    e = 0
  }
  let f
  try {
    f = b.toString().split('.')[1].length
  } catch (err) {
    f = 0
  }
  const c = Number(a.toString().replace('.', ''))
  const d = Number(b.toString().replace('.', ''))
  return mul(c / d, Math.pow(10, f - e))
}
